package com.woniu.job.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.job.entity.Work;
import com.woniu.job.mapper.WorkMapper;
import com.woniu.job.service.IWorkService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.job.util.Helper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;


/**
 * <p>
 * 服务实现类
 * 状态：1、正在招聘，2、招聘结束，3、招聘审核中
 * 性别：m 男     f  女   s 保密
 * 职业性质:1全职 2兼职  3实习
 * 是否允许应届生应聘:y是 n否
 *
 * </p>
 *
 * @author song
 * @since 2019-12-24
 */
@Service
public class WorkServiceImpl extends ServiceImpl<WorkMapper, Work> implements IWorkService {

    @Autowired
    private WorkMapper workMapper;

    @Override
    public IPage<Work> getByPage(Integer p,String id) {
        QueryWrapper<Work> queryWrapper = new QueryWrapper<>();
          queryWrapper.eq("companyId",id);
        Page<Work> page = new Page<>(p, 5);
        IPage<Work> iPage = workMapper.selectPage(page, queryWrapper);
        return iPage;
    }

    /**
     * @param id
     * @return：根据企业id查询到发布的职位信息
     */
    @Override
    public List<Work> getWorksById(String id) {
        return workMapper.getWorksById(id);
    }

    /**
     * @param id
     * @return:根据职位id查询招聘信息，企业信息
     */
    @Override
    public Work getCompWorkById(String id) {
        return workMapper.getCompWorkById(id);
    }

    /**
     * @return:根据类别查询职位信息
     */
    @Override
    public List<Work> getWorksByName(String name) {
        return workMapper.getWorksByName(name);
    }

    @Override
    public void refresh(String id) {
        Work work = new Work();
        work.setId(id);
        work.setValidTime(LocalDateTime.now());
        workMapper.updateById(work);
    }

    @Override
    public void delete(String id) {
        Work work = new Work();
        work.setId(id);
        work.setStatus("2");
        workMapper.updateById(work);
    }

    @Override
    public void add(Work work) {
        work.setId(Helper.getId());
        work.setValidTime(LocalDateTime.now());
        work.setStatus("1");
        workMapper.insert(work);
    }

    /**
     * 首页招聘职位展示
     *
     * @return：所有职位展示
     */
    @Override
    public List<Work> getWorksMap() {
        return workMapper.getWorksMap();
    }

    /**
     * 首页：最新职位-最新更新时间
     *
     * @return：按照时间的先后顺序查询
     */
    @Override
    public List<Work> getWorkByTime() {
        return workMapper.getWorkByTime();
    }

}
